<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <include file="./Public/Admin/header.html" />
    <script type="text/javascript" src="__PUBLIC__js/resource.js?2013-10-15-2"></script>
</head>
<body>
<div id="main">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="box">
                    <div class="box-title">
                        <div class="span10">
                            <h3><i class="icon-edit"></i>编辑图文消息     <small></small></h3>

                        </div>
                        <div class="span2"><a class="btn" onclick="javascript:window.history.go(-1);">返回</a></div>
                    </div>

                    <div class="box-content">

                        <form action="{:U('Admin/Wechat/editnew')}" method="POST" class="form-horizontal form-validate " >

                            <div class="control-group1 span12">

                                <div class="controls1" style="">

                                    <div id="edit_reply_box" class="edit_reply_box span12" style=" ">

                                        <div class="panel">
                                            <div class="image_edit_box">
                                                <div class="editBox">
                                                    <div class="leftMsg">
                                                        <div class="imgEdit imgnewsBox" id="imgEdit">
                                                            <if condition="$count gt 0">
                                                            <div  id="item_0">
                                                                <div class="caption div_caption" data-link="" data-link-name="">{$contents['detailtitle']}</div>
                                                                <div class="time">{$contents['addtime']}</div>
                                                                <div class="img">

                                                                    <div class="coverImg"><img src="{$contents['detaillogo']}"/></div>
                                                                </div>
                                                                <div class="des" id="div_digest">{$contents['detailintro']}</div>

                                                                <input  name="new[sortnum][0]" type="hidden" value="{$contents['sortnum']}" />
                                                                <input  name="new[detailtitle][0]" type="hidden" value="{$contents['detailtitle']}"/>
                                                                <input  name="new[detaillogo][0]" type="hidden" value="{$contents['detaillogo']}"/>
                                                                <input name="new[detailintro][0]" type="hidden" value="{$contents['detailintro']}"/>
                                                                <input  name="new[detailcontent][0]" type="hidden" value="{$contents['detailcontent']}"/>
                                                                <input name="new[linktype][0]" type="hidden" value=""/>
                                                                <input  name="new[detaillink][0]" type="hidden" value="{$contents['detaillink']}"/>
                                                            </div>
                                                            <else/>
                                                            <div  id="item_0">
                                                                <div class="caption div_caption" data-link="" data-link-name="">请输入标题</div>
                                                                <div class="time"><?php echo date('Y-m-d',time())?></div>
                                                                <div class="img">
                                                                    <div class="coverImg">封面图片</div>
                                                                </div>
                                                                <div class="des" id="div_digest"></div>

                                                                <input  name="new[sortnum][0]" type="hidden" value="0" />
                                                                <input  name="new[detailtitle][0]" type="hidden" value=""/>
                                                                <input  name="new[detaillogo][0]" type="hidden" value=""/>
                                                                <input name="new[detailintro][0]" type="hidden" value=""/>
                                                                <input  name="new[detailcontent][0]" type="hidden" value=""/>
                                                                <input name="new[linktype][0]" type="hidden" value=""/>
                                                                <input  name="new[detaillink][0]" type="hidden" value=""/>
                                                            </div>
                                                            </if>
                                                        </div>
                                                    </div>
                                                    <div class="rightEdit" id="rightEdit" data-index="0" style="padding-top:0px;">
                                                        <div class="rightEditBox">
                                                            <i class="a"></i><i class="b"></i>
                                                            <div class="sp">标题</div>
                                                            <div class="input">
                                                                <input type="text" value="{$contents['detailtitle']}" id="txt_caption" name="txt_caption" class="span12 required" />
                                                            </div>
                                                            <div class="sp">
                                                                封面<span id="imgmsg" class="pull-right" style="font-size: 12px; font-weight: normal;;">大图片建议尺寸：720像素 * 400像素</span>
                                                            </div>
                                                            <div class="input">
                                                                <button type="button" class="btn" onClick="upImage();"><i class=" icon-upload"></i> 上传</button><br />
                                                                <img id="thumb_img" src="{$contents['detaillogo']}" style="max-height:80px;display: <?php echo $count>0?'block':'none'?>;" />

                                                            </div>
                                                            <div class="sp">摘要</div>
                                                            <div class="input">
                                                                <textarea id="txt_intro" name="txt_intro" class="span12 "  style="height:50px;">{$contents['detailintro']}</textarea>
                                                            </div>
                                                            <div class="sp">详细内容</div>
                                                            <div class="input">
                                                                <textarea id="txt_content" name="txt_content" class="span12" style="height:10px;">
                                                                    {$contents['detailcontent']}
                                                                </textarea>

                                                            </div>
                                                            <div id="res_block" class="clearfix">
                                                                <div id="r_link" class=" r-module ">
                                                                    <div class="sp">图文链接地址(url)</div>
                                                                    <div class="input">

                                                                        <input type="text" id="source_url" value="{$contents['detaillink']}" class="span12 " name="source_url" />

                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="edit_reply_box text-center" style="">

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="span12">
                                <input type="hidden" name="action" id="action" value="{$action}">
                                <input type="hidden" name="cid" id="cid" value="{$cid}">
                                <button id="bsubmit" type="submit" data-loading-text="提交中..." class="btn btn-primary">保存</button>
                                <!--<button type="button" class="btn btn-primary" id="btnSave">保存</button>-->
                                <a href="javascript:godebug()" class="btn hide"></a>
                                <a class="btn" onclick="javascript:window.history.go(-1);">返回</a>
                            </div>

                        </form>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script type="text/javascript" charset="utf-8" src="__PUBLIC__../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__../ueditor/ueditor.all.js"></script>

<script type="text/javascript">
    //设置编辑器参数
    var param="type=<?php echo isset($utype)?$utype:''?>&comid=<?php echo isset($comid)?$comid:''?>&aid=<?php echo isset($accountid)?$accountid:''?>";
    var options = {
        initialFrameWidth:"100%",
        initialFrameHeight: 260,
        imageUrl:window.UEDITOR_CONFIG.UEDITOR_HOME_URL+"php/imageUp.php?"+param,
        fileUrl:window.UEDITOR_CONFIG.UEDITOR_HOME_URL+"php/fileUp.php?"+param,
        imageManagerUrl:window.UEDITOR_CONFIG.UEDITOR_HOME_URL + "php/imageManager.php?"+param,
        toolbars:[
            [ 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist',  '|',

                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'indent',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
                'link', 'unlink', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'insertimage', 'emotion',  'horizontal','|','help']
        ]
    };
    var ue = UE.getEditor('txt_content', options);
</script>
<script type="text/plain" id="upload_ue" style="display: none;"></script>
<script type="text/javascript">

    //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
    var _editor = UE.getEditor('upload_ue',options);
    _editor.ready(function () {
        //设置编辑器不可用
        _editor.setDisabled();
        //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
        _editor.hide();
        //侦听图片上传
        _editor.addListener('beforeInsertImage', function (t, arg) {
            //将地址赋值给相应的input,只去第一张图片的路径
            //$("#thumb").attr("value", arg[0].src);
            //$("#thumb").addClass('hide');
            //图片预览
            //$("#thumb_img").attr("src", arg[0].src);
            //$("#thumb_img").show();
            uploadImgCallBack(arg[0].src);
        })

        //侦听文件上传，取上传文件列表中第一个上传的文件的路径
        _editor.addListener('afterUpfile', function (t, arg) {
            $("#file").attr("value", _editor.options.filePath + arg[0].url);
        })
    });
    //弹出图片上传的对话框
    function upImage() {
        var myImage = _editor.getDialog("insertimage");
        myImage.open();
    }
    //弹出文件上传的对话框
    function upFiles() {
        var myFiles = _editor.getDialog("attachment");
        myFiles.open();
    }
</script>
<script type="text/javascript">

    $(document).ready(function () {


        var resource = Resource.create();
        var ins = Resource.instance['res_block'];
        ins.result = ins.result || {};
        //ins.result.aid = 9118;
    });
</script>

<script type="text/javascript">
    function godebug(){
        var i=$("#rightEdit").attr("data-index");
        //var a=$("input[name='new[sortnum][0]']").val();
        alert(i);
    }
    //取编辑器值 内容
    ue.addListener( "selectionchange", function () {
        var content=ue.getContent();//取值
        //设置值 ue.setContent('')
        //$('#conmsg').html(content);
        var i = $("#rightEdit").attr("data-index");
        if(!ue.hasContents()){
            //content='';
        }
        $("input[name='new[detailcontent]["+i+"]']").val(content);
    })
    //输入框 标题
    $("#txt_caption").keyup(function () {
        var i = $("#rightEdit").attr("data-index");
        $('#item_'+i).find(".div_caption").eq(0).html($(this).val());
        //赋值
        $("input[name='new[detailtitle]["+i+"]']").val($(this).val());
    });
    //输入框 摘要
    $("#txt_intro").keyup(function () {
        var i = $("#rightEdit").attr("data-index");
        $('#item_'+i).find(".des").eq(0).html($(this).val());
        //$('#item_'+i).find(".div_content").eq(0).html($(this).val());
        $("input[name='new[detailintro]["+i+"]']").val($(this).val());
    });
    $("#type").change( function() {
        var i = $("#rightEdit").attr("data-index");
        $("input[name='new[linktype]["+i+"]']").val($(this).val());
    });
    //链接
    $('#source_url').keyup(function(){
        var i = $("#rightEdit").attr("data-index");
        $("input[name='new[detaillink]["+i+"]']").val($(this).val());
    })
    //图片
    function uploadImgCallBack(src)
    {
        $("#thumb_img").attr("src", src);
        $("#thumb_img").show();
        var i = $("#rightEdit").attr("data-index");
        var img = "<img src='"+src+"' />";
        $('#item_'+i).find(".coverImg").eq(0).html(img);
        $("input[name='new[detaillogo]["+i+"]']").val(src);
    }


    $("#bsubmit").click(function(e){

        //检查是否添加
        $("input[name^='new[sortnum]']").each(function(){
            i=$(this).val();

            var title=$("input[name='new[detailtitle]["+i+"]']").val();
            if(title==''){
                alert('标题不能为空!');
                e.preventDefault();
                return false;
            }
            var logo=$("input[name='new[detaillogo]["+i+"]']").val();
            if(logo==''){
                alert('必须插入一张图片！');
                e.preventDefault();
                return false;
            }
            var con=$("input[name='new[detailcontent]["+i+"]']").val();
            var link=$("input[name='new[detaillink]["+i+"]']").val();
            if(con==''&&link==''){
                alert('正文或链接必须插入一项！');
                e.preventDefault();
                return false;
            }

        })

    })

</script>

</body>
</html>
